# source:https://leetcode.cn/submissions/detail/593292064/ 滑窗 二刷 一刷 24.8.4
class Solution:
    def countCompleteSubarrays(self, nums: List[int]) -> int:
        ans = 0
        i = 0
        d = defaultdict(int)
        n = len(set(nums))
        for j, v in enumerate(nums):
            d[v] += 1
            while len(d) == n:
                d[nums[i]] -= 1
                if d[nums[i]] == 0:
                    del d[nums[i]]
                i += 1
            ans += i
        return ans

# source:https://leetcode.cn/submissions/detail/593137740/ 枚举，几何
class Solution:
    def largestSquareArea(self, bottomLeft: List[List[int]], topRight: List[List[int]]) -> int:
        ans = 0
        for i in range(len(bottomLeft)-1):
            for j in range(i+1, len(bottomLeft)):
                point1, point2 = bottomLeft[i], topRight[i]
                point3, point4 = bottomLeft[j], topRight[j]
                width = min(point2[0], point4[0]) - max(point1[0], point3[0])
                height = min(point2[1], point4[1]) - max(point1[1], point3[1])
                size = min(width, height)
                ans = max(ans, size*size) if size > 0 else ans
        return ans
        # for ((x1, y1), (x2, y2)), ((x3, y3), (x4, y4)) in combinations(zip(bottomLeft, topRight), 2):
        #     width = min(x2, x4) - max(x1, x3)  # 注：改成用 if-else 计算 min 和 max 会更快
        #     height = min(y2, y4) - max(y1, y3)
        #     size = min(width, height)
        #     if size > 0:
        #         ans = max(ans, size * size)
        # return ans